package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.kaishengit.pojo.Idea;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;
import com.kaishengit.util.CreateTime;
import com.kaishengit.util.MyUUID;
import com.kaishengit.util.Outtime;

@Service
@Transactional
public class IdeaService extends BaseService {
	
	public List<Idea> findAll() {
		return getIdeaDao().findAll();
	}
	public List<Idea> getIdeas(Project project) {

		List<Idea> idea = getIdeaDao().findByProject(project);
		for (int i = 0; i < idea.size(); i++) {
			idea.get(i).setOuttime(
					Outtime.OutDateTime(idea.get(i).getCreatetime()));
		}
		return idea;
	}
	public void save(Idea idea, Project project,User user) {
		
		idea.setId(MyUUID.createUUID().toString());
		idea.setCreatetime(CreateTime.createTime());
		idea.setProject(project);
		idea.setUser(user);
		
		getIdeaDao().save(idea);

	}
	public Idea findById(String id) {
		return getIdeaDao().findById(id);
	}
	public void update(Idea idea, Project project, User user) {
		
		idea.setCreatetime(CreateTime.createTime());
		idea.setProject(project);
		idea.setUser(user);
		getIdeaDao().save(idea);
		
	}


}
